home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / PCIRQ.C < prev    next >
C/C++ Source or Header  |  1989-08-10  |  2KB  |  106 lines

  1. /* Hardware interrupt dependent stuff for IBM-PC running MS-DOS */
  2.  
  3. #include "global.h"
  4.  
  5. /* This flag is set by setirq() if IRQ 8-15 is used, indicating
  6.  * that the machine is a PC/AT with a second 8259 interrupt controller.
  7.  * If this flag is set, the interrupt return code in pcgen.asm will
  8.  * send an End of Interrupt command to the second 8259 as well as the
  9.  * first.
  10.  */
  11. extern char isat;
  12.  
  13. /* Install hardware interrupt handler.
  14.  * Takes IRQ numbers from 0-7 (0-15 on AT) and maps to actual 8086/286 vectors
  15.  * Note that bus line IRQ2 maps to IRQ9 on the AT
  16.  */
  17. setirq(irq,handler)
  18. unsigned irq;
  19. void (*handler)();
  20. {
  21.     /* Set interrupt vector */
  22.     if(irq < 8){
  23.         setvect(8+irq,handler);
  24.     } else if(irq < 16){
  25.         isat = 1;
  26.         setvect(0x70 + irq - 8,handler);
  27.     } else {
  28.         return -1;
  29.     }
  30.     return 0;
  31. }
  32. /* Return pointer to hardware interrupt handler.
  33.  * Takes IRQ numbers from 0-7 (0-15 on AT) and maps to actual 8086/286 vectors
  34.  */
  35. void
  36. (*getirq(irq))()
  37. unsigned int irq;
  38. {
  39.     void (*getvect())();
  40.  
  41.     /* Set interrupt vector */
  42.     if(irq < 8){
  43.         return getvect(8+irq);
  44.     } else if(irq < 16){
  45.         return getvect(0x70 + irq - 8);
  46.     } else {
  47.         return NULLVFP;
  48.     }
  49. }
  50. /* Disable hardware interrupt */
  51. maskoff(irq)
  52. unsigned irq;
  53. {
  54.     if(irq < 8){
  55.         setbit(0x21,(char)(1<<irq));
  56.     } else if(irq < 16){
  57.         irq -= 8;
  58.         setbit(0xa1,(char)(1<<irq));
  59.     } else {
  60.         return -1;
  61.     }
  62.     return 0;
  63. }
  64. /* Enable hardware interrupt */
  65. maskon(irq)
  66. unsigned irq;
  67. {
  68.     if(irq < 8){
  69.         clrbit(0x21,(char)(1<<irq));
  70.     } else if(irq < 16){
  71.         irq -= 8;
  72.         clrbit(0xa1,(char)(1<<irq));
  73.     } else {
  74.         return -1;
  75.     }
  76.     return 0;
  77. }
  78. /* Return 1 if specified interrupt is enabled, 0 if not, -1 if invalid */
  79. getmask(irq)
  80. unsigned irq;
  81. {
  82.     if(irq < 8)
  83.         return (inportb(0x21) & (1 << irq)) ? 0 : 1;
  84.     else if(irq < 16){
  85.         irq -= 8;
  86.         return (inportb(0xa1) & (1 << irq)) ? 0 : 1;
  87.     } else
  88.         return -1;
  89. }
  90.  
  91. /* Set bit(s) in I/O port */
  92.  
  93. setbit(port,bits)
  94. unsigned port;
  95. char bits;
  96. {
  97.     outportb(port,(char)inportb(port)|bits);
  98. }
  99. /* Clear bit(s) in I/O port */
  100. clrbit(port,bits)
  101. unsigned port;
  102. char bits;
  103. {
  104.     outportb(port,(char)(inportb(port) & ~bits));
  105. }
  106.